// $Id: handler.h 59 2011-04-23 07:49:29Z cedric.shih@gmail.com $
/*
 * Copyright (C) 2011 Cedric Shih <cedric.shih@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef NIOHANDLER_H_
#define NIOHANDLER_H_

#ifdef __cplusplus
extern "C" {
#endif

struct niochannel;

typedef int (*niohandler_setup_cb)(void *obj, const char *name);

typedef int (*niohandler_teardown_cb)(void *obj);

typedef int (*niohandler_handle_cb)(void *obj,
		struct niochannel *channel, void *message);

typedef void (*niohandler_free_cb)(void *obj);

struct niohandler {
	niohandler_setup_cb setup;
	niohandler_teardown_cb teardown;
	niohandler_handle_cb handle_upstream;
	niohandler_handle_cb handle_downstream;
	niohandler_free_cb free;
};

struct niobuffer *niochannel_buffer(struct niochannel *channel);

enum niochannel_direction {
	NIOCHANNEL_UPSTREAM,
	NIOCHANNEL_DOWNSTREAM,
};

enum niochannel_direction niochannel_direction(struct niochannel *channel);

int niochannel_keep_alive(struct niochannel *channel);

int niochannel_is_kept_alive(struct niochannel *channel);

int niochannel_send_upstream(struct niochannel *channel, const char *name,
		void *message);

int niochannel_send_downstream(struct niochannel *channel, const char *name,
		void *message);

#ifdef __cplusplus
}
#endif

#endif /* NIOHANDLER_H_ */
